package com.dingwen.treasure.file.config;

import lombok.SneakyThrows;
import net.bramp.ffmpeg.FFmpeg;
import net.bramp.ffmpeg.FFprobe;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 　FfmpegConfig
 * 　@author dingwen
 * 　@date 2022/7/28
 */
@Configuration
public class FfmpegConfig {

    @Resource
    private M3U8Properties m3U8Properties;

    @SneakyThrows(Throwable.class)
    @Bean
    public FFmpeg fFmpeg() {
        return isLinux() || isMac() ? new FFmpeg(m3U8Properties.getFfmpegPath()) : null;
    }

    @SneakyThrows(Throwable.class)
    @Bean
    public FFprobe fFprobe() {
        return isLinux() || isMac() ? new FFprobe(m3U8Properties.getFfprobePath()) : null;
    }


    /**
     * linux
     *
     * @return boolean
     */
    public static boolean isLinux() {
        return System.getProperty("os.name").toLowerCase().contains("linux");
    }

    /**
     * mac os
     *
     * @return boolean
     */
    public static boolean isMac() {
        return System.getProperty("os.name").toLowerCase().contains("mac");
    }

    /**
     * windows
     *
     * @return boolean
     */
    public static boolean isWindows() {
        return System.getProperty("os.name").toLowerCase().contains("windows");
    }
}
